<script setup lang="ts">
  import JsInterface from "vite-xiongan-jssdk";
  import { ref } from "vue";
  import { pdfbase64 } from "./pdfbase64";

  console.log(JsInterface);
  const device = new JsInterface.SDKInterface({
    success: (res: any) => {
      // 初始话成功
      console.log(res);
    },
    fail: (err: any) => {
      // 初始话失败
      console.log(err);
    },
  });
  // console.log(device)
  // device.initSocket();
  const testFunc = {
    success: (res: any) => {
      const response = res;
      console.log(response);
    },
    fail: (err: any) => {
      const error = err;
      console.log(error);
    },
  };

  const getIdCardFunc = () => {
    device.getIDCard(testFunc);
  };

  const closeIdCardFunc = () => {
    device.closeIdCard(testFunc);
  };

  const readBarcodeFunc = () => {
    device.readBarcode(testFunc);
  };

  const closeBcrFunc = () => {
    device.closeBcr(testFunc);
  };

  const getPrinterListFunc = () => {
    device.getPrinterList(testFunc);
  };

  const getPrintQueueFunc = () => {
    device.getPrintQueue({
      strPrinter: "NPI2F5626 (HP LaserJet Pro MFP M521dw)",
      success: (res) => {
        console.log(res);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };

  const printPrrFunc = () => {
    let strData = `\r\n
  \r\n交通银行客户通知书
  \r\n
  \r\n设备编号:  ABBG875
  \r\n受理行号:  01310999999
  \r\n终端流水号:  516016
  \r\n交易时间:  2022年02月14日 15时50分16秒
  \r\n交易类型:  借记卡挂失补卡
  \r\n卡号:  6222 62** **** ***2 775
  \r\n姓名:  *计龙
  \r\n记名卡补卡成功
  \r\n补卡方式:  网点自提`;

    device.printPrr({
      strData: strData,
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };

  const testHeighCamShow = () => {
    device.getHighCameraStream({
      height: 300,
      width: 300,
      x: 0,
      y: 0,
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testHeighCamCloseShow = () => {
    device.closeHighCamera({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testHeighCamGetImage = () => {
    device.getHighCamera({
      success: (stream) => {
        console.log(stream.data);
      },
      fail: (err) => {
        console.log(err.data);
      },
    });
  };

  const printerFunc = () => {
    // "C:/fp.pdf", "ET788C775065B8"
    device.printer({
      printerName: "ET788C775065B8",
      fileType: "PDF",
      fileData: pdfbase64,
      pageFormat: "2", // 1,横向  2纵向  PDF按默认打印，目前支持 PDF打印

      success: (res) => {
        const response = res;
        console.log(response);
      },
      fail: (err) => {
        const error = err;
        console.log(error);
      },
    });
  };
  const testFaceCamShow = () => {
    device.getVideoCamera({
      height: 300,
      width: 300,
      x: 0,
      y: 0,
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testFaceCamCloseShow = () => {
    device.closeVideoCamera({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testFaceCamGetImage = () => {
    device.getDoubleCamera({
      mode: "checkLiving",
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testFaceCamGetImage2 = () => {
    device.getDoubleCamera({
      mode: "picture",
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testPinInput = () => {
    device.getNumLock({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testPinInputClose = () => {
    device.closeNumLock({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };

  const fingerId = ref<HTMLInputElement>();
  const testSaveFingerTemplate = () => {
    if (fingerId.value) {
      device.saveFingerTemplate({
        fingerId: fingerId.value.value,
        success: (stream) => {
          console.log(stream);
        },
        fail: (err) => {
          console.log(err);
        },
      });
    }
  };
  const testDelteFingerTemplate = () => {
    device.deleteFingerTemplate({
      fingerId: "1",
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
    device.deleteFingerTemplate({
      fingerId: "2",
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testReadFinger = () => {
    device.readFinger({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testVerifyFinger = () => {
    device.verifyFinger({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testCloseFinger = () => {
    device.closeFinger({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
  const testGetNetWokerInfo = () => {
    device.getNetworkAddr({
      success: (stream) => {
        console.log(stream);
      },
      fail: (err) => {
        console.log(err);
      },
    });
  };
</script>

<template>
  <div>测试</div>
  <button @click="testHeighCamShow">测试高拍仪预览</button>
  <button @click="testHeighCamCloseShow">测试高拍仪关闭预览</button>
  <button @click="testHeighCamGetImage">测试高拍仪获取照片</button>
  <button @click="testFaceCamShow">测试人脸预览</button>
  <button @click="testFaceCamCloseShow">测试人脸关闭预览</button>
  <button @click="testFaceCamGetImage">测试人脸获取照片</button>
  <button @click="testFaceCamGetImage2">
    测试人脸获取照片(不等待活体检测)
  </button>
  <button @click="getIdCardFunc">测试身份证读卡</button>
  <button @click="closeIdCardFunc">测试取消读卡</button>
  <button @click="readBarcodeFunc">测试二维码扫描</button>
  <button @click="closeBcrFunc">测试取消二维码扫描</button>
  <button @click="printPrrFunc">测试打印凭条</button>
  <button @click="getPrinterListFunc">测试获取打印机名称列表</button>
  <button @click="getPrintQueueFunc">测试获取打印队列列表</button>
  <button @click="printerFunc">测试获取打印PDF文档</button>
  <button @click="testPinInput">测试密码键盘输入</button>
  <button @click="testPinInputClose">测试取消密码键盘输入</button>
  <button @click="testSaveFingerTemplate">测试保存指纹模板</button>
  <button @click="testDelteFingerTemplate">测试删除指纹模板</button>
  <button @click="testReadFinger">测试读取指纹特征值</button>
  <button @click="testVerifyFinger">测试对比指纹特征值</button>
  <button @click="testCloseFinger">测试取消指纹命令</button>
  <button @click="testGetNetWokerInfo">设备网络地址</button>
  <div class="show">123</div>
  <input type="numer" ref="fingerId" value="1" />
  <!-- <button @click="closeIdCard">测试凭条打印</button>
  <button @click="closeIdCard">测试取消凭条打印</button>
  <button @click="closeIdCard">测试A4打印</button>
  <button @click="closeIdCard">测试取消A4打印</button> -->
</template>

<style scoped>
  button,
  div.show {
    margin: 12px;
    width: 200px;
    height: 60px;
    border-radius: 0.25rem;
    border: 1px solid #dedede;
  }
</style>
